{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 新建面矢量数据"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## wkt:\n",
    "point:'POINT(30,10)'\n",
    "linestring:'LINESTRING(30 10,10 30,20 20)'\n",
    "### 面有可能有空洞，有两层括号，可能有更多的点定义中空位置\n",
    "polygon:'POLYGON((30 10,10 30,20 20))'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (1990674696.py, line 3)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Cell \u001b[1;32mIn[1], line 3\u001b[1;36m\u001b[0m\n\u001b[1;33m    path_ynu_vector=\u001b[0m\n\u001b[1;37m                    ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "from osgeo import ogr\n",
    "from osgeo import osr\n",
    "path_ynu_vector=\"D:\\Lenovo\\Desktop\\云南大学\\开源地理信息系统\\output\\YunnanUniversity_Polygon\"\n",
    "ynu_wkt='POLYGON ((102.839 24.832,102.840 24.836, 102.845 24.837, 102.855 24.837, 102.858 24.834, 102.864 24.828,))'\n",
    "geo_ynu=ogr.CreateGeometryFromWkt(ynu_wkt)\n",
    "\n",
    "driver=ogr.GetDriverByName('ESRI Shapefile')\n",
    "ds_ynu=driver.CreateDataSource(path_ynu_vector)\n",
    "SpatialRef=osr.SpatialReference()\n",
    "SpatialRef.ImportFromEPSG(4326)\n",
    "layer_ynu=ds_ynu.CreateLayer('ynu_vec',srs=SpatialRef,geom_type=ogr.wkbPolygon)\n",
    "fea_defn=layer_ynu.GetLayerDefn()\n",
    "field_defn=ogr.FieldDefn('fid',ogr.OFTInteger)\n",
    "layer_ynu.CreateField(field_defn)\n",
    "fea_ynu=ogr.Feature(fea_defn)\n",
    "fea_ynu.SetField('fid',11)\n",
    "fea_ynu.SetGeometry(geo_ynu)\n",
    "layer_ynu.CreateFeature(fea_ynu)\n",
    "\n",
    "ds_ynu=None\n",
    "\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.18"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
